#!/bin/bash

# 一键启停hadoop集群。

if [ $# -lt 1 ]; then
    echo "Usage: myhadoop.sh start/stop"
    exit
fi

HDFS_LOC=hadoop100
YARN_LOC=hadoop101
HIS_LOC=hadoop100
HD_HOME=/opt/module/hadoop-3.1.3/

case $1 in

"start")
    echo ==================== 启动 hadoop 集群 ==========================

    echo -------------------- 启动 hdfs --------------------------------
    ssh $HDFS_LOC "$HD_HOME/sbin/start-dfs.sh"

    echo -------------------- 启动 yarn --------------------------------
    ssh $YARN_LOC "$HD_HOME/sbin/start-yarn.sh"

    echo -------------------- 启动 historyserver --------------------------------
    ssh $HIS_LOC "$HD_HOME/bin/mapred --daemon start historyserver"
    ;;

"stop")
    echo ==================== 关闭 hadoop 集群 ==========================

    echo -------------------- 关闭 historyserver --------------------------------
    ssh $HIS_LOC "$HD_HOME/bin/mapred --daemon stop historyserver"

    echo -------------------- 关闭 yarn --------------------------------
    ssh $YARN_LOC "$HD_HOME/sbin/stop-yarn.sh"

    echo -------------------- 关闭 hdfs --------------------------------
    ssh $HDFS_LOC "$HD_HOME/sbin/stop-dfs.sh"
    ;;

*)
    echo "Invalid input"
    ;;
esac
